package com.iseastar.dianxiaosan.home.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.dianxiaosan.model.TradeRecordBean;
import com.iseastar.guojiang.app.Intents;
import com.shouhuobao.station.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import droid.frame.activity.base.BaseAdapterExt;

public class TradeRecordAdapter extends BaseAdapterExt<TradeRecordBean> {

	private SimpleDateFormat sdf;

	public TradeRecordAdapter(ArrayList<TradeRecordBean> items, Activity context) {
		super(items, context);
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.trade_record_item, parent, false);
			holder.number = (TextView) convertView.findViewById(R.id.guojiang_phone);
			holder.name = (TextView) convertView.findViewById(R.id.guojiang_name);
			holder.time = (TextView) convertView.findViewById(R.id.trade_parcel_time);
			holder.num = (TextView) convertView.findViewById(R.id.trade_parcel_num);
			holder.phone = (ImageView) convertView.findViewById(R.id.trade_phone);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final TradeRecordBean item = items.get(position);

		holder.number.setText("电话: " + item.getMobile());// 裹将电话
		holder.name.setText("火箭侠: " + item.getCourierName());// 裹将名称
		holder.num.setText("交接包裹数: " + item.getParcelCount());// 交接包裹数

		Date date = new Date(item.getJoinTime());
		String time = sdf.format(date);
		holder.time.setText("交接时间: " + time);// 交接时间

		holder.phone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intents.dialOrCall(item.getMobile());
			}
		});
		return convertView;
	}

	private static class ViewHolder {
		TextView num, number, name, time;
		ImageView phone;
	}

}
